/*
"DataType":"FormData",
"BBox":[l,t,r,b],
"matrix":[a,b,c,d,e,f],
"ObjArray":[Obj1, Obj2, ...],
"genStateData":[state1, state2, ...],
"clrStateData":[state1, state2, ...],
"textStateData":[state1, state2, ...],
"graphStateData":[state1, state2, ...],
"clipPathStateData":[state1, state2, ...]
}
*/


function PDForm(pdDoc, csImgPath) {
    this.pdPageObjects = null;
    this.m_csImgPath = csImgPath;
    this.m_pdDoc = pdDoc;
}


PDForm.prototype.CountObj = function() {
    return this.pdPageObjects.objectArr.length;
};


PDForm.prototype.GetObj = function(i) {
    if (i < 0 || i >= this.pdPageObjects.objectArr.length) {
		return null;
	}
	else {
	    return this.pdPageObjects.objectArr[i];
	}
};



PDForm.prototype.GetMatrixByID = function(id) {
    return this.pdPageObjects.GetMatrixByID;
};

// **************** 4 states *********************************

PDForm.prototype.CountGenState = function() {
	return this.pdPageObjects.genStates.length;
};

PDForm.prototype.GetGenStateByID = function (id) {
	for (var i = 0; i < this.pdPageObjects.genStates.length; i++) {
		if (id == this.pdPageObjects.genStates[i].uID) {
			return this.pdPageObjects.genStates[i];
		}
	}
	return null;
};

PDForm.prototype.GetGenStateByIndex = function (index) {
	if (index < 0 || index >= this.pdPageObjects.genStates.length) {
		return null;
	}
	return this.pdPageObjects.genStates[index];
};


PDForm.prototype.CountGraphState = function () {
	return this.pdPageObjects.graphStates.length;
};

PDForm.prototype.GetGraphStateByID = function (id) {
	for (var i = 0; i < this.pdPageObjects.graphStates.length; i++) {
		if (id == this.pdPageObjects.graphStates[i].uID) {
			return this.pdPageObjects.graphStates[i];
		}
	}
	return null;
};

PDForm.prototype.GetGraphStateByIndex = function (index) {
	if (index < 0 || index >= this.pdPageObjects.graphStates.length) {
		return null;
	}
	return this.pdPageObjects.graphStates[index];
};


PDForm.prototype.CountClrState = function () {
	return this.pdPageObjects.clrStates.length;
};


PDForm.prototype.GetClrStateByID = function (id) {
	for (var i = 0; i < this.pdPageObjects.clrStates.length; i++) {
		if (id == this.pdPageObjects.clrStates[i].uID) {
			return this.pdPageObjects.clrStates[i];
		}
	}
	return null;
};

PDForm.prototype.GetClrStateByIndex = function(index) {
	if (index < 0 || index >= this.pdPageObjects.clrStates.length) {
		return null;
	}
	return this.pdPageObjects.clrStates[index];
};


PDForm.prototype.CountTextState = function () {
	return this.pdPageObjects.textStates.length;
};

PDForm.prototype.GetTextStateByID = function (id) {
	for (var i = 0; i < this.pdPageObjects.textStates.length; i++) {
		if (id == this.pdPageObjects.textStates[i].uID) {
			return this.pdPageObjects.textStates[i];
		}
	}
	return null;
};

PDForm.prototype.GetTextStateByIndex = function (index) {
	if (index < 0 || index >= this.pdPageObjects.textStates.length) {
		return null;
	}
	return this.pdPageObjects.textStates[i];
};


PDForm.prototype.CountClipPathState = function() {
	return this.pdPageObjects.clpathStates.length; 
};


PDForm.prototype.GetClipPathStateByID = function (id) {
	for (var i = 0; i < this.pdPageObjects.clpathStates.length; i++) {
		if (id == this.pdPageObjects.clpathStates[i].uID) {
			return this.pdPageObjects.clpathStates[i];
		}
	}
	return null;
};

PDForm.prototype.GetClipPathStateByIndex = function (index) {
	if (index < 0 || index >= this.pdPageObjects.clpathStates.length) {
		return null;
	}
	return this.pdPageObjects.clpathStates[i];
};

// *************************************************************



PDForm.prototype.GetPageObjects = function () {
    return this.pdPageObjects;

};



PDForm.prototype.ParseFromBin = function (rd) {
    this.pdPageObjects = new PDPageObjects(this.m_pdDoc);
    this.pdPageObjects.type = 1;
    this.pdPageObjects.m_csImgPath = this.m_csImgPath;
    //this.pdPageObjects.m_pdPage = this.m_pdPage;
    this.pdPageObjects.ParseFromBin(rd);
};

